﻿using System;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Windows.Media.Animation;
using System.Windows;

namespace SymulatorEthernetWPF.UserInterface.UIElements
{
    internal class CustomLabel : Label
    {

        private DoubleAnimation animationFadeIn=new DoubleAnimation();
        private Storyboard storyFadeIn=new Storyboard();
        private DoubleAnimation animationFadeOut = new DoubleAnimation();
        private Storyboard storyFadeOut = new Storyboard();

        public CustomLabel()
        {
            this.Loaded += new RoutedEventHandler(CustomLabel_Loaded);
        }
        void CustomLabel_Loaded(object sender, RoutedEventArgs e)
        {
            animationFadeIn.From = 0;
            animationFadeIn.To = 1;
            animationFadeIn.Duration = TimeSpan.FromSeconds(0.1);
            Storyboard.SetTarget(animationFadeIn, this);
            Storyboard.SetTargetProperty(animationFadeIn, new PropertyPath(CustomLabel.OpacityProperty));
            storyFadeIn.Children.Add(animationFadeIn);


            animationFadeOut.From = 1;
            animationFadeOut.To = 0;
            animationFadeOut.BeginTime = TimeSpan.FromSeconds(0.5);
            animationFadeOut.Duration = TimeSpan.FromSeconds(0.5);
            Storyboard.SetTarget(animationFadeOut, this);
            Storyboard.SetTargetProperty(animationFadeOut, new PropertyPath(CustomLabel.OpacityProperty));
            storyFadeOut.Children.Add(animationFadeOut);
        }

        public void ShowMessage(string message, bool fadeout = false)
        {
            Content = message;
            this.BeginStoryboard(storyFadeIn);
            
        }

        public void FadeOut()
        {
            this.BeginStoryboard(storyFadeOut); ;
        }


    }
}